import 'package:get/get.dart';
import 'package:yysk_app/model/pay_model/list_bank_branch_hf_model.dart';
import 'package:yysk_app/pages/nft_pages/pay_pages/select_bank_branch_list/select_bank_list_branch_controller.dart';

import 'package:flutter/material.dart';
import 'package:yysk_app/pages/nft_pages/wallet_pages/manage_bank/add_bank_card_controller.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';
import 'package:yysk_app/widget/empty_widget.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';

class SelectBankListBranchPage extends GetView<SelectBankListBranchController> {
  static const String path = '/SelectBankListBranchPage';
  const SelectBankListBranchPage({super.key});

  @override
  Widget build(BuildContext context) {
    final double top = MediaQuery.of(context).padding.top;
    return Scaffold(
      body: Stack(
        children: [
          //添加背景色，代码如下：
          SizedBox(
            width: context.width,
            child: ImageAssetWidget(
              width: double.infinity,
              height: 173.px,
              imageUrl: 'static/images/wallet/top_bg.png',
            ),
          ),
          Column(
            children: [
              Expanded(
                child: Padding(
                  padding: EdgeInsets.fromLTRB(0, top, 0, 24.px),
                  child: Column(
                    children: [
                      CustomAppBar2(title: '银行支行列表', context: context),
                      Expanded(
                        child: SingleChildScrollView(
                          physics: AlwaysScrollableScrollPhysics(),
                          padding: EdgeInsets.all(21.px),
                          child: SizedBox(
                            width: context.width,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                Container(
                                  width: 346.px,
                                  // height: 37.px,
                                  padding: EdgeInsets.only(
                                    left: 12.px,
                                    right: 14.px,
                                  ),
                                  decoration: BoxDecoration(
                                    color: AppColors.backgroundColor,
                                    borderRadius: BorderRadius.circular(6.px),
                                  ),
                                  child: Stack(
                                    children: [
                                      Center(
                                        child: TextField(
                                          
                                          controller: controller.nameController,
                                          onChanged: (value) {
                                            // 使用Timer，2秒后执行
                                            // if (value.length >= 18) {
                                            //   Timer(const Duration(seconds: 1), () {
                                            //     print('2秒后执行');
                                            //     addBankCardHfController.isBindCard();
                                            //     // 在这里调用你想要延迟执行的方法
                                            //   });
                                            // }
                                          },
                                          maxLength: 20,
                                          decoration: InputDecoration(
                                            constraints: BoxConstraints(
                                              minWidth: context.width
                                            ),
                                            contentPadding:
                                                EdgeInsets.symmetric(
                                                  // vertical: 12.px,
                                                ),
                                            border: InputBorder.none,
                                            counterText: '',
                                            hintText: '请输入关键词搜索',
                                            hintStyle: TextStyle(
                                              color: AppColors.fontColorGrey,
                                            ),
                                          ),
                                          style: TextStyle(
                                            color: AppColors.fontColorBlack,
                                          ),
                                        ),
                                      ),
                                      Positioned(
                                        right: 0.px,
                                        top: 14.px,
                                        child: ImageAssetWidget(imageUrl: 'static/images/mall/find.png',width: 14.px,height: 14.px))
                                    ],
                                  ),
                                ),
                                // ignore: invalid_use_of_protected_member
                                 Container(
                                  decoration: BoxDecoration(
                                    // color: AppColors.backgroundColorLightGreen
                                  ),
                                  child: 
                                  Obx(()=>
                                  controller.filteredBanks.isNotEmpty? Column(
                                    children: [
                                      ...controller.filteredBanks.map((e) {
                                        return   _buildItem(item: e);
                                      })
                                    
                                    ],
                                  ):EmptyWidget()),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
  _buildItem( {required ListBankBranchHfModel item}){
    return 
   GestureDetector(
    // onTap: (){
    //   AddBankCardHfController addBankCardHfController = Get.find();
    //   addBankCardHfController.branchName.value = item.branchName??'';
    //   addBankCardHfController.branchCode.value = item.branchCode??'';
    //   Get.back();
    // },
      onTap: (){
     if(controller.type.value=='add'){
      //  AddBankCardHfController addBankCardHfController = Get.find();
      // addBankCardHfController.branchName.value = item.branchName??'';
      // addBankCardHfController.branchCode.value = item.branchCode??'';
      Get.back();
     }else{
      AddBankCardController addBankCardController = Get.find();
      addBankCardController.branchName.value = item.branchName??'';
      addBankCardController.branchCode.value = item.branchCode??'';
           Get.back();
     }
    },
    child:  Container(
      margin: EdgeInsets.only(top: 12.px),
      padding: EdgeInsets.fromLTRB(12.px, 14.px, 25.px, 15.px),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6.px),
        color: AppColors.backgroundColor,
          boxShadow: [
            BoxShadow(
              color: AppColors.backgroundColorBlack.withAlpha(25),
              offset: const Offset(0, 14),
              blurRadius: 24,
              spreadRadius: 0,
            ),
          ],
      ),
      width: 346.px,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text('${item.branchName}',style: TextStyle(fontSize: 14.px,color: AppColors.backgroundColorBlack,fontFamily: 'CustomPINGFANG'),),
       
        ],
      ),
    ),
   );
  }
}
